<template>
	<view style="height: 100vh; background-color: #FFFFFF;">
		<u-navbar title-color="#FFFFFF" height="48" back-icon-color="#FFFFFF" :border-bottom="false" :is-fixed="true" :title="'隐患工单'"></u-navbar>
		<u-form ref="workOrderFrom" :model="workOrderFrom" label-width="100px" class="wrap">
			<u-form-item  label="工单名称" prop="name" >
				<u-input :border="border"   v-model="workOrderFrom.name" placeholder="请输入工单名称" ></u-input>
			</u-form-item>
			<u-form-item  label="隐患地点" prop="address" >
				<u-input :border="border"   v-model="workOrderFrom.address" placeholder="请输入隐患地点" ></u-input>
			</u-form-item>
			<u-form-item  label="隐患详情" prop="remark" >
				<u-input :border="border"   v-model="workOrderFrom.remark" placeholder="描述:如一楼监控室烟感损坏需更换" ></u-input>
			</u-form-item>
			<u-button @click="submit" type="primary">提交</u-button>
		</u-form>			
	</view>
</template>


<script>
	export default {
		data() {
			return {
				workOrderFrom:{
					equipmentId:'',
					status:0,
					name:'',
					address:'',
					remark:''
				},
				border:true,
				rules:{
					name: [
						{
							required: true,
							message: '请输入工单名称',
							trigger: ['change','blur']
						},
					],
					address: [
						{
							required: true,
							message: '请输入隐患地点',
							trigger: ['change','blur']
						},
					],
					remark: [
						{
							required: true,
							message: '请描述隐患详情',
							trigger: ['change','blur']  
						},
					],
				}
				
			}
		},
		onReady() {
			this.$refs.workOrderFrom.setRules(this.rules);
		},
		onLoad(e) {
			console.log(e)
			this.workOrderFrom.equipmentId = e.ucId
		},
		onShow() {
	
		},
		methods: {			
			submit(){
				this.$refs.workOrderFrom.validate(valid => {
					if (valid) {
						this.utils.request("/api/app/inHiddenDanger/generateHiddenDanger", this.workOrderFrom, "post", "app", true).then(res => {
							this.utils.request("/api/app/user/getUserInfo", {}, "get", "app", true).then(res => {
								if(res.data.roleCode == "XZ-ADMIN" || res.data.roleCode == "XZ-YH"){
									//消灾企业用户
									uni.redirectTo({
										url:"/pages/index/index_xz"
									})
								} else if(res.data.roleCode == "WB-ADMIN" || res.data.roleCode == "WB-YH"){
									//维保企业用户
									uni.redirectTo({
										url:"/pages/index/index_wb"
									})
								}else if(res.data.roleCode == "JC-ADMIN" || res.data.roleCode == "JC-YH"){
									//维保企业用户
									uni.redirectTo({
										url:"/pages/index/index_jc"
									})
								}else{
									//其他企业用户
									uni.redirectTo({
										url:"/pages/index/index_qt"
									})
								}
							}).catch(error => {
								console.log(error)
							})
						}).catch(error => {
							console.log(error)
						})
					} else {
						console.log('验证失败');
					}
				});
			}
		}
	}
</script>

<style>

</style>
